Skip to content

Enhancement: isolate LiveDebugger injected assets from debugged app#964

Merged
kraleppa merged 5 commits into
mainfrom
660-put-livedebugger-js-inside-iframe
Apr 3, 2026
Merged

Enhancement: isolate LiveDebugger injected assets from debugged app#964
kraleppa merged 5 commits into
mainfrom
660-put-livedebugger-js-inside-iframe

Conversation

@kraleppa
Copy link
Copy Markdown
Member

@kraleppa kraleppa commented Apr 2, 2026

The goal here was to isolate assets injected via LiveDebugger to debugged application. Initially the idea was to do it via iframe, but since there is a problem of different origin (you cannot access window.parent.document from iframe that has different origin, and in our case it has, since LiveDebugger is hosted on different port) and our logic is not that big I decided to do it via shadow DOM

Example: If user has aggressive styling (in this case font, color of button etc) or JS scripts (accessing LiveDebugger button element)

Main:
Screenshot 2026-04-02 at 12 25 44

This branch:
Screenshot 2026-04-02 at 12 26 13

@kraleppa kraleppa linked an issue Apr 2, 2026 that may be closed by this pull request
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request isolates LiveDebugger's injected assets (UI elements and styles) from the debugged application by moving them into a Shadow DOM. Instead of serving the CSS as a separate HTTP request and injecting it into the page head, the CSS is now loaded directly into the shadow DOM, preventing style conflicts between LiveDebugger and the application's own stylesheets.

Changes:

  • Removed CSS URL from server-side configuration and replaced with direct shadow DOM CSS loading
  • Created shadow host with closed mode Shadow DOM to encapsulate debugger UI
  • Updated all client-side functions to accept and use shadowRoot parameter for DOM manipulation
  • Enhanced CSS with proper styling rules (box-sizing, font-family) for isolated rendering
  • Implemented proper event handling for shadow DOM elements using composedPath for cross-boundary clicks

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lib/live_debugger/client/config_component.ex Removed css_url attribute and link tag injection
lib/live_debugger.ex Removed @css_path constant and css_url variable assignment
assets/client/client.js Created shadow DOM host with CSS link, passed shadowRoot to init functions
assets/client/components/debug_menu.js Updated to mount elements in shadowRoot, added composedPath-based click handling
assets/client/services/inspect.js Added debugButton parameter to avoid DOM queries
assets/client/services/highlight.js Updated to use shadowRoot for DOM queries and element appending
assets/client/components/tooltip/tooltip.js Updated to use shadowRoot for DOM queries and element appending
assets/client/components/tooltip/tooltip_creator.js Updated to append tooltip to shadowRoot instead of document.body
assets/client/client.css Added box-sizing and font-family rules for better isolation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@hhubert6 hhubert6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐬

Comment thread phoenix_live_reload Outdated
@kraleppa kraleppa merged commit 9ccff96 into main Apr 3, 2026
4 checks passed
@kraleppa kraleppa deleted the 660-put-livedebugger-js-inside-iframe branch April 3, 2026 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Put LiveDebugger JS inside iframe

3 participants